package dm71.espil.activities;

import dm71.espil.R;
import dm71.espil.R.layout;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class SplashActivity extends Activity {
	
	protected boolean _active = true;
	protected int _splashTime = 1000; // time to display splashscreen
	SplashActivity context = this;
	
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        
        //Thread for displaying the SplashScreen
        Thread splashThread = new Thread() 
        {
        	@Override
        	public void run()
        	{
        		try
        		{
        			int waited = 0;
        			while(_active && (waited < _splashTime))
        			{
        				sleep(100);
        				if(_active)
        				{
        					waited += 100;
        				}
        			}
        		}
        		catch(InterruptedException e)
        		{
        			// do nothing
        		}
        		finally
        		{
        			finish();
        	        Intent intent = new Intent(context, LoginActivity.class);
        	        startActivity(intent);
        			this.interrupt();
        		}
        	}
        	
        };
        splashThread.start();
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
    	if (event.getAction() == MotionEvent.ACTION_DOWN)
    	{
    		_active = false;
    	}
    	return true;
    }
}
